A dedicated command processing chip is used to process one or more commands predefined by a system. For example, a router is dedicated to processing data forwarding. As a scale of data processing chips becomes larger, there are more on-chip memories. To reduce a scale of memories, a shared cache is used in some places that do not need a full-thread cache so as to reduce memory resources. Therefore, design and management of the shared cache is especially important. To facilitate allocation and management of the cache, the shared cache is divided into multiple cache units with a same size, and the size of the cache units may be preset according to actual requirements of command processing.
A command processing procedure of a functional module responsible for command processing in a chip is generally: when the module receives a to-be-processed command from a programmable processor, parsing the command to confirm whether the command needs to cache data; if the command needs to cache data, allocating a cache unit to the to-be-processed command in a clock cycle, writing associated data that does not participate in data processing such as a thread identity (ID) of the to-be-processed command into the allocated cache unit, and performing command processing; in a command processing process, always storing the associated data in the cache unit; and after the command processing is completed, reading the associated data in the cache unit and releasing the cache unit.
To facilitate cache management, generally, cache units are of only one size. With diversification and complication of chip command processing, a problem that the size of the cache units is set unreasonably becomes prominent. If a cache unit with a small granularity is used, when a volume of data that the to-be-processed command needs to cache is relatively large, multiple clock cycles are needed for completing caching the data once. Consequently, cache efficiency is low. If a cache unit with a large granularity is used, when a volume of data that the to-be-processed command needs to cache is relatively small, waste of cache resources is caused.
It can be learned that how to both improve the cache efficiency and reduce the waste of the cache resources becomes a problem to be resolved urgently.